/**
 * 
 */
package model;

import java.awt.TextArea;
import java.io.StreamCorruptedException;

import view.ChatView;

import model.Program;

import com.sun.media.jsdt.ChannelConsumer;
import com.sun.media.jsdt.Data;

import controller.FileController;

/**
 * @author rika
 *
 */
public class ProgConsumer implements ChannelConsumer{
	private FileController fileController;
	private ChatView chatView;
	
	public ProgConsumer(FileController fileController,ChatView chatView){
		this.fileController = fileController;
		this.chatView = chatView;
	}

//	@Override
//	public synchronized void dataReceived(Data data) {
//		// TODO Auto-generated method stub
//	        String  theData    = data.getDataAsString();
//	        System.out.println("Prog Consumer :: "+ theData);
//	        //fileController.setUserName(theData);
//	        fileController.addNewUserToTree(fileController.getFileInfo());  
//	        chatView.addNewClient(theData);
//	}
	
	public synchronized void dataReceived(Data theData) {
		Program progRecu = null;
		try {
			
			progRecu = (Program) theData.getDataAsObject();
			this.fileController.traiterProgrammePartage(progRecu);
			chatView.addNewClient(progRecu.getOwner());
			
		} catch (StreamCorruptedException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
//	@Override
//	public synchronized void dataReceived(Data data) {
//		// TODO Auto-generated method stub
//	        FileInfo theData;
//			try {
//				theData = (FileInfo)data.getDataAsObject();
//		        System.out.println("Prog Consumer :: "+ theData);
//		        fileController.addNewUserToTree(theData);  
//		        chatView.addNewClient(theData.getProprietaire());
//			} catch (StreamCorruptedException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			} catch (ClassNotFoundException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//
//	}
}
